package com.lyz.moil.core.security.service;

import java.util.List;

import javax.annotation.Resource;

import com.lyz.moil.core.security.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lyz.moil.core.orm.hibernate.BaseDao;
import com.lyz.moil.core.orm.hibernate.BaseService;
import com.lyz.moil.core.security.dao.RolesDao;
import com.lyz.moil.core.security.entity.Roles;

@Service
@Transactional
public class UserService extends BaseService<User> {
	@Resource(name = "rolesDao")
	private RolesDao rolesDao;

	@Override
	@Resource(name = "userDao")
	public void setBaseDao(BaseDao<User> baseDao) {
		this.baseDao = baseDao;
	}

	public List<Roles> findAllRoles() {
		return rolesDao.findAll();
	}
	
	public User findUserByAccount(String account) {
		List<User> userList = baseDao.findListByQuestionMark("from User as o where o.account = ? ", account);
		if (userList != null && !userList.isEmpty()) {
			return userList.get(0);
		} else {
			return null;
		}
	}
	
	public List<User> findMenu() {
		return baseDao.findList("from User as o inner join o.roles as r where o. = 1 order by gorder");
	}

}
